//
//  SharePanel.m
//  NetEaseFinancial
//
//  Created by 吴玉峰 on 8/27/15.
//  Copyright (c) 2015 吴玉峰. All rights reserved.
//

#import "NFSSharePanel.h"

#import "ZPActionSheetView.h"
#import "WYFShareHolder.h"
#import "WYFSharePanelAdapter.h"
#import "WYFSendToWeChatFriendAction.h"
#import "WYFShareOnWeChatMomentAction.h"
#import "WYFSendToEasyChatFriendAction.h"
#import "WYFShareOnEasyChatMomentAction.h"
#import "WYFOpenInBrowserAction.h"
#import "WYFCopyLinkAction.h"
#import "WYFSendViaSmsAction.h"
#import "WYFShareOnSinaWeiboAction.h"

static NSArray *kShareActions = nil;

@interface NFSSharePanel ()

@property (nonatomic, strong) WYFJSCommand *cmd;
@property (nonatomic, strong) WYFShareHolder *holder;
@property (nonatomic, strong) ZPActionSheetView *actionSheet;

@end

@implementation NFSSharePanel

- (instancetype)initSharePanelWithHolder:(WYFShareHolder *)holder
                                     cmd:(WYFJSCommand *)cmd {
    if ((self = [super init])) {
        self.holder = holder;
        self.cmd = cmd;
        [self initShareActions];
        [self setContentView];
    }
    return self;
}

- (void)initShareActions {
    if (kShareActions == nil) {
        kShareActions = @[
            [[WYFSendToWeChatFriendAction alloc] init],
            [[WYFShareOnWeChatMomentAction alloc] init],
            [[WYFSendToEasyChatFriendAction alloc] init],
            [[WYFShareOnEasyChatMomentAction alloc] init],
            [[WYFOpenInBrowserAction alloc] init],
            [[WYFCopyLinkAction alloc] init],
            [[WYFSendViaSmsAction alloc] init],
            [[WYFShareOnSinaWeiboAction alloc] init]
        ];
    }
}

- (void)setContentView {
    WYFSharePanelAdapter *adapter = [[WYFSharePanelAdapter alloc] initWithShareActions:kShareActions];
    self.actionSheet = [[ZPActionSheetView alloc] initWithSharePanelAdapter:adapter];
    __strong WYFShareHolder *holder = self.holder;
    [self.actionSheet setBtnClick:^(NSInteger btnTag) {
        WYFBaseShareAction *action = kShareActions[btnTag];
        //NSLog(@"\n点击第几个====%@\n当前选中的按钮title====%@", btnTag, [action getLabelName]);
        NSLog(@"setContentView.url:%@", holder.webUrl);
        [action shareWithHolder:holder];
    }];
}

- (void)show {
    [[UIApplication sharedApplication].windows[0] addSubview:self.actionSheet];
}

@end
